import json
from collections import Counter
from datetime import datetime, timedelta

import requests
from flask import Flask, request, jsonify
from flask_cors import CORS

app = Flask(__name__)
CORS(app)

event_data_list = [
    {'id': '1', 'name': '新活动1', 'address': '广州市天河区', 'contactPhone': '13911981097', 'serviceType': '社区服务',
     'serviceStart': '2024-03-08 09:08', 'serviceEnd': '2024-03-08 15:08', 'money': '56',
     'introduce': '25-40,新活动介绍1', 'gender': '男', 'peopleNum': '10', 'contactName': '张小强'},
    {'id': '2', 'name': '新活动2', 'address': '深圳市宝安区', 'contactPhone': '13942163634', 'serviceType': '儿童关爱',
     'serviceStart': '2024-03-08 09:08', 'serviceEnd': '2024-03-08 14:08', 'money': '181',
     'introduce': '25-40,新活动介绍2', 'gender': '不限', 'peopleNum': '22', 'contactName': '赵小云'},
    {'id': '3', 'name': '新活动3', 'address': '广州市番禺区', 'contactPhone': '13953164066', 'serviceType': '社区服务',
     'serviceStart': '2024-03-08 09:08', 'serviceEnd': '2024-03-08 10:08', 'money': '159',
     'introduce': '30-40,新活动介绍3', 'gender': '男', 'peopleNum': '24', 'contactName': '赵小云'},
    {'id': '4', 'name': '新活动4', 'address': '广州市番禺区', 'contactPhone': '13918760668', 'serviceType': '社区服务',
     'serviceStart': '2024-03-08 09:08', 'serviceEnd': '2024-03-08 17:08', 'money': '93',
     'introduce': '25-40,新活动介绍4', 'gender': '女', 'peopleNum': '16', 'contactName': '李小红'},
    {'id': '5', 'name': '新活动5', 'address': '广州市天河区', 'contactPhone': '13919430627', 'serviceType': '老年关怀',
     'serviceStart': '2024-03-08 09:08', 'serviceEnd': '2024-03-08 14:08', 'money': '104',
     'introduce': '18-24,新活动介绍5', 'gender': '不限', 'peopleNum': '21', 'contactName': '王小明'},
    {'id': '6', 'name': '新活动6', 'address': '深圳市宝安区', 'contactPhone': '13913220027', 'serviceType': '社区服务',
     'serviceStart': '2024-03-08 09:08', 'serviceEnd': '2024-03-08 14:08', 'money': '192',
     'introduce': '25-40,新活动介绍6', 'gender': '女', 'peopleNum': '10', 'contactName': '赵小云'},
    {'id': '7', 'name': '新活动7', 'address': '广州市天河区', 'contactPhone': '13959217774', 'serviceType': '教育支持',
     'serviceStart': '2024-03-08 09:08', 'serviceEnd': '2024-03-08 13:08', 'money': '124',
     'introduce': '不限,新活动介绍7', 'gender': '不限', 'peopleNum': '21', 'contactName': '王小明'},
    {'id': '8', 'name': '新活动8', 'address': '深圳市宝安区', 'contactPhone': '13999435487', 'serviceType': '社区服务',
     'serviceStart': '2024-03-08 09:08', 'serviceEnd': '2024-03-08 17:08', 'money': '107',
     'introduce': '18-24,新活动介绍8', 'gender': '不限', 'peopleNum': '29', 'contactName': '赵小云'},
    {'id': '9', 'name': '新活动9', 'address': '深圳市宝安区', 'contactPhone': '13976768786', 'serviceType': '老年关怀',
     'serviceStart': '2024-03-08 09:08', 'serviceEnd': '2024-03-08 14:08', 'money': '183',
     'introduce': '18-24,新活动介绍9', 'gender': '不限', 'peopleNum': '23', 'contactName': '张小强'},
    {'id': '10', 'name': '新活动10', 'address': '深圳市福田区', 'contactPhone': '13924633884',
     'serviceType': '社区服务', 'serviceStart': '2024-03-08 09:08', 'serviceEnd': '2024-03-08 10:08', 'money': '51',
     'introduce': '不限,新活动介绍10', 'gender': '不限', 'peopleNum': '15', 'contactName': '王小明'},
    {'id': '11', 'name': '新活动11', 'address': '广州市天河区', 'contactPhone': '13935878393',
     'serviceType': '社区服务', 'serviceStart': '2024-03-08 09:08', 'serviceEnd': '2024-03-08 11:08', 'money': '79',
     'introduce': '30-40,新活动介绍11', 'gender': '男', 'peopleNum': '10', 'contactName': '李小红'},
    {'id': '12', 'name': '新活动12', 'address': '深圳市福田区', 'contactPhone': '13931604816',
     'serviceType': '儿童关爱', 'serviceStart': '2024-03-08 09:08', 'serviceEnd': '2024-03-08 12:08', 'money': '92',
     'introduce': '25-40,新活动介绍12', 'gender': '女', 'peopleNum': '22', 'contactName': '王小明'},
    {'id': '13', 'name': '新活动13', 'address': '深圳市福田区', 'contactPhone': '13965185151',
     'serviceType': '老年关怀', 'serviceStart': '2024-03-08 09:08', 'serviceEnd': '2024-03-08 17:08', 'money': '86',
     'introduce': '不限,新活动介绍13', 'gender': '不限', 'peopleNum': '9', 'contactName': '张小强'},
    {'id': '14', 'name': '新活动14', 'address': '深圳市宝安区', 'contactPhone': '13906048067',
     'serviceType': '儿童关爱', 'serviceStart': '2024-03-08 09:08', 'serviceEnd': '2024-03-08 13:08', 'money': '133',
     'introduce': '不限,新活动介绍14', 'gender': '男', 'peopleNum': '23', 'contactName': '王小明'},
    {'id': '15', 'name': '新活动15', 'address': '广州市番禺区', 'contactPhone': '13977408749',
     'serviceType': '老年关怀', 'serviceStart': '2024-03-08 09:08', 'serviceEnd': '2024-03-08 12:08', 'money': '157',
     'introduce': '25-40,新活动介绍15', 'gender': '女', 'peopleNum': '18', 'contactName': '赵小云'},
    {'id': '16', 'name': '新活动16', 'address': '广州市天河区', 'contactPhone': '13939664266',
     'serviceType': '儿童关爱', 'serviceStart': '2024-03-08 09:08', 'serviceEnd': '2024-03-08 13:08', 'money': '162',
     'introduce': '25-40,新活动介绍16', 'gender': '男', 'peopleNum': '15', 'contactName': '张小强'},
    {'id': '17', 'name': '新活动17', 'address': '深圳市宝安区', 'contactPhone': '13968151285',
     'serviceType': '老年关怀', 'serviceStart': '2024-03-08 09:08', 'serviceEnd': '2024-03-08 16:08', 'money': '197',
     'introduce': '不限,新活动介绍17', 'gender': '不限', 'peopleNum': '21', 'contactName': '张小强'},
    {'id': '18', 'name': '新活动18', 'address': '深圳市宝安区', 'contactPhone': '13984998477',
     'serviceType': '社区服务', 'serviceStart': '2024-03-08 09:08', 'serviceEnd': '2024-03-08 13:08', 'money': '56',
     'introduce': '不限,新活动介绍18', 'gender': '男', 'peopleNum': '29', 'contactName': '赵小云'},
    {'id': '19', 'name': '新活动19', 'address': '深圳市福田区', 'contactPhone': '13911613961',
     'serviceType': '儿童关爱', 'serviceStart': '2024-03-08 09:08', 'serviceEnd': '2024-03-08 11:08', 'money': '88',
     'introduce': '30-40,新活动介绍19', 'gender': '男', 'peopleNum': '9', 'contactName': '张小强'},
    {'id': '20', 'name': '新活动20', 'address': '广州市番禺区', 'contactPhone': '13924522639',
     'serviceType': '老年关怀', 'serviceStart': '2024-03-08 09:08', 'serviceEnd': '2024-03-08 14:08', 'money': '107',
     'introduce': '不限,新活动介绍20', 'gender': '不限', 'peopleNum': '30', 'contactName': '王小明'},
    {'id': '21', 'name': '新活动21', 'address': '深圳市福田区', 'contactPhone': '13991627284',
     'serviceType': '老年关怀', 'serviceStart': '2024-03-08 09:08', 'serviceEnd': '2024-03-08 14:08', 'money': '179',
     'introduce': '18-24,新活动介绍21', 'gender': '女', 'peopleNum': '18', 'contactName': '李小红'},
    {'id': '22', 'name': '新活动22', 'address': '广州市番禺区', 'contactPhone': '13983703448',
     'serviceType': '教育支持', 'serviceStart': '2024-03-08 09:08', 'serviceEnd': '2024-03-08 10:08', 'money': '121',
     'introduce': '25-40,新活动介绍22', 'gender': '男', 'peopleNum': '29', 'contactName': '王小明'},
]

user_event_list = [
    {'id': '1', 'name': '新活动1', 'address': '深圳市福田区', 'contactPhone': '13996535580', 'serviceType': '社区服务',
     'serviceStart': '2024-03-08 09:08', 'serviceEnd': '2024-03-08 13:08', 'money': '148',
     'introduce': '25-40,新活动介绍1', 'peopleNum': '18', 'contactName': '王小明'},
    {'id': '2', 'name': '新活动2', 'address': '深圳市福田区', 'contactPhone': '13937307387', 'serviceType': '社区服务',
     'serviceStart': '2024-03-08 09:08', 'serviceEnd': '2024-03-08 13:08', 'money': '144',
     'introduce': '30-40,新活动介绍2', 'peopleNum': '16', 'contactName': '张小强'},
    {'id': '3', 'name': '新活动3', 'address': '深圳市宝安区', 'contactPhone': '13969086021', 'serviceType': '教育支持',
     'serviceStart': '2024-03-08 09:08', 'serviceEnd': '2024-03-08 14:08', 'money': '145',
     'introduce': '25-40,新活动介绍3', 'peopleNum': '15', 'contactName': '王小明'},
    {'id': '4', 'name': '新活动4', 'address': '广州市天河区', 'contactPhone': '13920206186', 'serviceType': '教育支持',
     'serviceStart': '2024-03-08 09:08', 'serviceEnd': '2024-03-08 14:08', 'money': '128',
     'introduce': '不限,新活动介绍4', 'peopleNum': '18', 'contactName': '张小强'},
    {'id': '5', 'name': '新活动5', 'address': '深圳市宝安区', 'contactPhone': '13943744055', 'serviceType': '教育支持',
     'serviceStart': '2024-03-08 09:08', 'serviceEnd': '2024-03-08 13:08', 'money': '142',
     'introduce': '18-24,新活动介绍5', 'peopleNum': '15', 'contactName': '张小强'},
    {'id': '6', 'name': '新活动6', 'address': '深圳市宝安区', 'contactPhone': '13900652168', 'serviceType': '教育支持',
     'serviceStart': '2024-03-08 09:08', 'serviceEnd': '2024-03-08 14:08', 'money': '151',
     'introduce': '25-40,新活动介绍6', 'peopleNum': '16', 'contactName': '王小明'},
    {'id': '7', 'name': '新活动7', 'address': '广州市天河区', 'contactPhone': '13933540079', 'serviceType': '教育支持',
     'serviceStart': '2024-03-08 09:08', 'serviceEnd': '2024-03-08 13:08', 'money': '121',
     'introduce': '25-40,新活动介绍7', 'peopleNum': '17', 'contactName': '李小红'},
    {'id': '8', 'name': '新活动8', 'address': '深圳市福田区', 'contactPhone': '13946294707', 'serviceType': '社区服务',
     'serviceStart': '2024-03-08 09:08', 'serviceEnd': '2024-03-08 13:08', 'money': '120',
     'introduce': '18-24,新活动介绍8', 'peopleNum': '17', 'contactName': '王小明'},
    {'id': '9', 'name': '新活动9', 'address': '广州市天河区', 'contactPhone': '13936232731', 'serviceType': '社区服务',
     'serviceStart': '2024-03-08 09:08', 'serviceEnd': '2024-03-08 14:08', 'money': '160',
     'introduce': '18-24,新活动介绍9', 'peopleNum': '19', 'contactName': '王小明'}

]

"""
   自定义权重分值

   地址分数值 如：深圳市-龙岗区
   城市的分数 - self.address_city_point = address_city_point 
   区域的分数 - self.address_area_point = address_area_point

   服务类型分数值 如：社区服务
   self.service_type_point = service_type_point

   服务时间分数值 
   self.service_time_point = service_time_point

   服务价格分数值
   self.service_price_point = service_price_point

   服务年龄段分数值
   self.service_age_point = service_age_point

   服务人数分数值
   self.service_people_point = service_people_point

   自定义范围数

   时间范围数
   self.time_range+ = time_range+
   self.time_range- = time_range-

   价格范围数
   self.price_range+ = price_range+
   self.price_range- = price_range-

   人数范围数
   self.people_range+ = people_range+
   self.people_range- = people_range-
"""

# 计算用户权重各项参数的值
all_user_recommend_weight = {
    "address_city_point": 2,
    "address_area_point": 2,
    "service_type_point": 1,
    "service_time_point": 1,
    "service_price_point": 2,
    "service_age_point": 1,
    "service_people_point": 1,

    "time_range+": 2,
    "time_range-": 2,
    "price_range+": 30,
    "price_range-": 30,
    "people_range+": 5,
    "people_range-": 5,
}

# 用户的信息
user_info = {
    "age": 20,
    "name": "zs"
}

# 最终推荐多少条数据给用户
result_recommend_num = 4

# 使用用户历史的多少条数据进行权重计算
user_history_event_num = 5


class MyRecommend:
    def __init__(self, event_data_list, user_event_list, all_user_recommend_weight, user_info, user_history_event_num,
                 result_recommend_num):
        self.recommend_user_event_data_list_weight = None
        self.user_recommendation_weight = None
        self.event_data_list = event_data_list
        self.user_event_list = user_event_list
        self.result_recommend_num = result_recommend_num

        # 将数据初始化（更新年龄字段）
        self.update_data_fields()

        self.all_user_recommend_weight = all_user_recommend_weight
        self.user_info = user_info
        self.user_history_event_num = user_history_event_num

    # 通过用户历史数据 计算出对应权重
    def recommend_user(self):

        # 地址字段
        address_list = []

        # 服务类型字段
        service_type_list = []

        # 服务时间字段
        service_time_list = []

        # 时间币字段
        time_coin_list = []

        # 服务建议的年龄
        service_age_list = []

        # 服务总人数
        service_people_num_list = []

        for i in range(self.user_history_event_num):
            event = self.user_event_list[i]
            address_list.append(event['address'])
            service_type_list.append(event['serviceType'])
            service_start = datetime.strptime(event['serviceStart'], '%Y-%m-%d %H:%M')  # 将字符串转换为 datetime 对象
            service_end = datetime.strptime(event['serviceEnd'], '%Y-%m-%d %H:%M')
            time_diff = service_end - service_start  # 计算时间差
            service_time_list.append(time_diff.total_seconds() // 3600)  # 将时间差转换为小时并加入列表
            time_coin_list.append(event['money'])

            user_age = 24  # 假设用户年龄为 25 岁

            if event['age'] == "不限":
                service_age_list.append('不限')
            else:
                min_age, max_age = map(int, event['age'].split('-'))
                if min_age <= user_age <= max_age:
                    service_age_list.append('正常')
                else:
                    service_age_list.append('不限')

            service_people_num_list.append(int(event['peopleNum']))  # 将参与人数转换为整数加入列表

        # 统计各字段出现的次数
        address_counts = Counter(address_list)
        service_type_counts = Counter(service_type_list)
        service_time_sum = sum(service_time_list)  # 服务时间总和
        time_coin_sum = sum(map(int, time_coin_list))  # 时间币总和
        service_people_num_sum = sum(service_people_num_list)  # 服务人数总和
        service_age_counts = Counter(service_age_list)
        service_people_num_counts = Counter(service_people_num_list)

        # 找出出现次数最多的字段
        # 使用Counter对象的most_common()方法来找出出现频率最高的元素
        # 参数1表示我们只想要找出出现频率最高的一个元素
        # 返回的结果是一个列表，其中包含一个元组，元组的第一个元素是出现频率最高的元素，第二个元素是它出现的次数
        # 通过索引[0]，选择了这个列表中的第一个元素，即出现频率最高的元素对应的元组
        # 最后一步是选择出现频率最高的元素，也就是元组中的第一个元素，因此使用索引[0]

        most_common_address = address_counts.most_common(1)[0][0]  # 最佳地址
        most_common_service_type = service_type_counts.most_common(1)[0][0]  # 最佳服务类型
        average_service_time = service_time_sum / len(service_time_list)  # 计算平均服务时间
        average_time_coin = time_coin_sum / len(time_coin_list)  # 计算平均时间币
        average_service_people_num = service_people_num_sum / len(service_people_num_list)  # 计算平均服务人数
        most_common_service_age = service_age_counts.most_common(1)[0][0]  # 平均服务活动年龄
        most_common_service_people_num = service_people_num_counts.most_common(1)[0][0]  # 平均服务活动人数

        # 添加用户推荐权重
        user_recommendation_weight = []
        user_recommendation_weight.append((
            most_common_address, most_common_service_type, average_service_time, average_time_coin,
            average_service_people_num, most_common_service_age, most_common_service_people_num))

        self.user_recommendation_weight = user_recommendation_weight

        # 打印结果
        print(f"======================用户：{user_info['name']}==========================")
        print("======================权重结果==========================")
        print("出现最多的地址：", most_common_address)
        print("出现最多的服务类型：", most_common_service_type)
        print("平均服务时间：", average_service_time)
        print("平均时间币：", average_time_coin)
        print("平均服务人数：", average_service_people_num)
        print("出现最多的服务年龄建议：", most_common_service_age)
        print("出现最多的服务总人数：", most_common_service_people_num)
        print("================================================")

    # 通过用户权重进行推荐，使用：可报活动数据、全局用户推荐权重、当前用户的权重
    def recommend_event(self):
        recommend_user_event_data_list_weight = []

        for event in self.event_data_list:

            # 找地址字段
            # 分别对城市和区域进行打分
            address_area_weight = 0
            address_city_weight = self.all_user_recommend_weight['address_city_point'] if event['address'].split("市")[
                                                                                              0] == \
                                                                                          self.user_recommendation_weight[
                                                                                              0][0].split("市")[
                                                                                              0] else 0
            if address_city_weight > 0:
                address_area_weight = self.all_user_recommend_weight['address_area_point'] if \
                    event['address'].split("市")[1] == self.user_recommendation_weight[0][0].split("市")[1] else 0
            address_weight = address_city_weight + address_area_weight

            # 找服务类型字段
            service_type_weight = self.all_user_recommend_weight['service_type_point'] if event['serviceType'] == \
                                                                                          self.user_recommendation_weight[
                                                                                              0][1] else 0

            # 找时间字段
            service_start = datetime.strptime(event['serviceStart'], '%Y-%m-%d %H:%M')  # 将字符串转换为 datetime 对象
            service_end = datetime.strptime(event['serviceEnd'], '%Y-%m-%d %H:%M')
            time_diff = service_end - service_start  # 计算时间差
            # 将平均服务时间转换为 timedelta 类型的对象
            average_service_time_timedelta = timedelta(hours=self.user_recommendation_weight[0][2])

            # 比较时间差是否在范围内
            service_time_weight = self.all_user_recommend_weight[
                'service_time_point'] if average_service_time_timedelta - timedelta(
                hours=1) <= time_diff <= average_service_time_timedelta + timedelta(hours=1) else 0

            # 找时间币字段
            time_coin_weight = self.all_user_recommend_weight['service_price_point'] if \
                self.user_recommendation_weight[0][3] - 20 <= int(event['money']) <= self.user_recommendation_weight[0][
                    3] + 20 else 0

            # 找服务人数字段
            service_people_num_weight = self.all_user_recommend_weight['service_people_point'] if \
                self.user_recommendation_weight[0][4] - 5 <= int(
                    event['peopleNum']) <= self.user_recommendation_weight[0][4] + 5 else 0

            # 找服务年龄字段
            service_age_weight = self.all_user_recommend_weight['service_age_point'] if event['age'] == \
                                                                                        self.user_recommendation_weight[
                                                                                            0][5] else 0

            # 计算总分数
            total_weight = address_weight + service_type_weight + service_time_weight + time_coin_weight + service_people_num_weight + service_age_weight

            recommend_user_event_data_list_weight.append((event['id'], total_weight))
        # 按照权重降序排列
        recommend_user_event_data_list_weight.sort(key=lambda x: x[1], reverse=True)
        self.recommend_user_event_data_list_weight = recommend_user_event_data_list_weight
        print(recommend_user_event_data_list_weight)

    # 返回推荐结果
    def get_recommend_user_list(self):
        recommendation_printed = 0
        recommend_user_list = []
        for event_id in self.recommend_user_event_data_list_weight:
            for event in self.event_data_list:
                if event['id'] == event_id[0]:
                    recommend_user_list.append(event)
                    recommendation_printed += 1

                    # 两次循环需要两次break
                    if recommendation_printed == self.result_recommend_num:
                        break
            if recommendation_printed == self.result_recommend_num:
                break
        return recommend_user_list

    # 通过调用接口进行获取数据：活动的数据
    # 如果接口用不了，就不要调用这个方法
    def get_events_data(self, user_json):
        try:
            # 获取可报名的列表
            response = requests.get("http://192.168.31.214:1006/queryAllActive")
            response.raise_for_status()  # 确保请求成功
            events_list = json.loads(response.text)
            self.event_data_list = events_list['data']

            # 获取当前用户的历史报名活动列表
            user_id = user_json['userId']  # 对 userId 进行 URL 编码
            response = requests.get(f"http://192.168.31.214:1006/queryAllActive?id={user_id}")
            response.raise_for_status()  # 确保请求成功
            user_events_list = json.loads(response.text)
            self.user_event_list = user_events_list['data']

            # 将数据初始化（更新年龄字段）
            self.update_data_fields()
            # 如果需要返回值，可以在这里返回
            # return self.event_data_list, self.user_event_list

        except requests.RequestException as e:
            print(f"Error occurred: {e}")

    # 将数据初始化（更新年龄字段）：活动列表 历史活动记录
    def update_data_fields(self):
        for i in range(len(self.event_data_list)):
            self.event_data_list[i]['age'] = self.event_data_list[i]['introduce'].split(',')[0]

        for i in range(len(self.user_event_list)):
            self.user_event_list[i]['age'] = self.user_event_list[i]['introduce'].split(',')[0]


@app.route('/')
def home():
    return 'Recommend!'


"""
getRecommendList 需要传一个用户信息

如：
{
    "age" :12,
    "name":"历史"
}

"""


@app.route('/getRecommendList', methods=['POST'])
def get_recommend_list():
    try:
        if request.method == 'POST':
            user_json = request.get_json()
            if not user_json or 'age' not in user_json or 'name' not in user_json:
                return "用户信息不完整或格式错误"

            # 初始化推荐系统
            recommend = MyRecommend(event_data_list, user_event_list, all_user_recommend_weight, user_info,
                                    user_history_event_num, result_recommend_num)

            # 如果区块链接口可以使用，则使用以下方法，获取最新数据：可报活动列表，用户历史活动列表
            # recommend.get_events_data(user_json)

            recommend.recommend_user()
            recommend.recommend_event()
            result = recommend.get_recommend_user_list()

            return jsonify(result)
        else:
            return "请求异常"

    except Exception as e:
        print(str(e))
        return "服务器开了个小差，请稍后再试"


"""
getUserRecommendWeight 需要传一个权重列表

如：
{
    "address_city_point": 2,
    "address_area_point": 2,
    "service_type_point": 1,
    "service_time_point": 1,
    "service_price_point": 2,
    "service_age_point": 1,
    "service_people_point": 1,
    "time_range+": 2,
    "time_range-": 2,
    "price_range+": 30,
    "price_range-": 30,
    "people_range+": 5,
    "people_range-": 5,
}

"""


@app.route('/getUserRecommendWeight', methods=['POST'])
def get_user_recommend_weight():
    if request.method == 'POST':
        user_recommend_weight_json = request.get_json()
        global all_user_recommend_weight
        all_user_recommend_weight = user_recommend_weight_json
        return jsonify(user_recommend_weight_json)
    else:
        return "请求异常"


"""
getUserRecommendCount 需要传两个值，一个为：将推荐给用户多少条活动，一个为：使用用户多少条历史活动数据来计算推荐权重
如：
{
    "result_recommend_num":5,
    "user_history_event_num":5
}

"""


@app.route('/getUserRecommendCount', methods=['POST'])
def get_user_recommend_count():
    if request.method == 'POST':
        user_recommend_count_json = request.get_json()
        global result_recommend_num, user_history_event_num
        result_recommend_num = user_recommend_count_json['result_recommend_num']
        user_history_event_num = user_recommend_count_json['user_history_event_num']

        return [result_recommend_num, user_history_event_num]
    else:
        return "请求异常"


if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000, debug=True)

# Todo
# 捕获每一个接口异常
# 校验每一个参数传递是否正确
# 具体参考get_recommend_list方法的实现效果

# FIXME

# NOTE

# BUG

# XXX

# HACK